<?php

class Default_Model_Appoint extends Zend_Db_Table_Abstract {
	private $db = null;
	protected $_name = 'appointment'; 
  	protected $_primary = 'appointment_id'; 
	public function init()
	{
		$this->db = Zend_Registry::get('DB');
	}
	
	public function updateAppoint($data,$id)
	{
		$date = new Zend_Date($data['appoint_date']);
		$sqlData = array(
			'date'		  => $date->get('Y-M-d'),
			'descriptions'=> $data['appoint_description']
		);
		$where = $this->_db->quoteInto("appointment_id = ?",$id);
		$this->update($sqlData,$where);
	}
	
	public function addAppoint($data)
	{
		$date = new Zend_Date($data['appoint_date']);
		$sqlData = array(
			'customer_id' => $data['appoint_customer'],
			'date'		  => $date->get('Y-M-d'),
			'descriptions'=> $data['appoint_description']
		);
		return $this->insert($sqlData);
	}
	public function getBookingbyDate($date)
	{
		if (!($date instanceof Zend_Date)) 
		{
			$date = new Zend_Date($date);
		}
		$select = $this->db->select();
//		$select = new Zend_Db_Select();
		$select->from(array('a' => 'appointment'),array('appointment_id','descriptions'))
		       ->joinInner(array('c' => 'customer'),'c.customer_id = a.customer_id',array('c.customer_id','c.customer_fname','c.customer_lname'))
		       ->where('a.date = ?',$date->get('Y-M-d'));
		return $this->db->query($select)->fetchAll(Zend_Db::FETCH_ASSOC);       
	}
	
	public function delApp($id)
	{
		$where = $this->db->quoteInto('appointment_id = ?', $id);
		return $this->delete($where);
	}
	public function getAppbyId($id)
	{
		$select = $this->_db->select();
		$select ->from(array('a'=>'appointment'),array('date','descriptions','appointment_id'))
				->joinInner(array('c' =>'customer'),'c.customer_id = a.customer_id',array('customer_id','customer_fname','customer_lname'))
				->where("a.appointment_id = ?",$id);
		return $data = $this->_db->fetchRow($select);
	}
}

?>